package com.doxiaopu.students.product.controller;

import com.doxiaopu.students.component.controller.BaseController;
import com.doxiaopu.students.component.result.ResponseResult;
import com.doxiaopu.students.product.service.IMyTaskVOService;
import com.doxiaopu.students.product.vo.MyTaskVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Api(tags = "任务信息")
@RestController
@CrossOrigin
@RequestMapping("/myTask")
public class MyTaskVOController extends BaseController {
    @Autowired
    private IMyTaskVOService iMyTaskVOService;
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    //查询任务列表
    @ApiOperation(value = "查询任务列表")
    @PostMapping("/inquireMyTaskVOList")
    @ResponseBody
    public ResponseResult<List<MyTaskVO>> inquireMyTaskVOList(HttpServletRequest request){
        Integer id =getUidFromRequest(request);
        if(id !=null) {
            List<MyTaskVO> data = iMyTaskVOService.myTaskList(id);
            System.err.print(data);
            return new ResponseResult<List<MyTaskVO>>(SUCCESS,data);
        }else {
            return new ResponseResult<List<MyTaskVO>>(408,"登录过期请重新登录");
        }
    }

    private Integer getUidFromRequest(HttpServletRequest request){
        //获取headers中的参数
        String token = request.getHeader("token");
        if(stringRedisTemplate.opsForValue().get(token) != null) {
            return Integer.valueOf(stringRedisTemplate.opsForValue().get(token).toString());
        }else {
            return null;
        }
    }
}
